#pragma once
#include <SDL/SDL.h>
#include "GameTile.h"
#include "GlobalStructs.h"
#include <list>
#include <ctime>
using namespace std;
/* temp values for tile size */


// may need to be static because there should only be one instance of it
class Board
{
public:
	Position m_idArray[20];		// position of the tiles in the source file
	Position m_gridStart;		// starting position of the grid
	SDL_Surface * m_bufferCopy;
private:
	// This enum is so you can pan the camera using the 
	// panCam(CameraMovement type) function
	enum CameraMovement {
		CAM_UP, CAM_DOWN, CAM_LEFT, CAM_RIGHT
	};

	/*--- Non-Class Variables ---*/
	SDL_Surface * m_gridImage;
	SDL_Surface * m_background;
	Player * m_players;		// array of players
	list<Tile> m_deck;		
	Position m_camFocus;	// where the camera is going to be focused on the screen // uses X-Y
	Position m_gridFocus;	// uses Column-Row
	GameTile ** m_gTiles;
	/*--- Member Variables ---*/
	int m_currentPlayer;	// index of current player
	bool m_isDrakonPlaced;

public:
	/*--- Constructors ---*/
	Board(SDL_Surface*);
	~Board();
	/*--- Game Functions ---*/
	bool panCam(CameraMovement cm);
//	bool mapChamberToPlayer
	// Get Functions
	//WARNING CHANGED on friday from list<Tile> getDeck(void); to list<Tile>& getDeck(void);
	list<Tile>& getDeck(void);
	list<Tile>& getDeckReference(void); //allows the list to be modified outside of
										//the class without having to make a set function :)
	Tile getGameTile(Position pos);
	Tile getGameTile(int r,int c);
	bool isDrakonPlaced(){return m_isDrakonPlaced;}
	void summonDrakon(Position pos);
	Player& getPlayer(int i) { return m_players[i];}
	int getCurrentPlayer() { return m_currentPlayer; }
	Tile getTopTileFromDeck(); //*will REMOVE the top element in list, becareful*
	GameTile ** getGameTiles() { return m_gTiles; }
	void givePlayerACard(int playerID);
	Tile getTopOfDeck() { return m_deck.front(); }
	void addATileToDeck(Tile tile) {m_deck.push_back(tile);}
	Position getGridFocus(void);
	Position getGridStart(void);
	int getTileTrueWidth(void);
	int getTileTrueHeight(void);
	int getBoardTileXPos(int);
	int getBoardTileYPos(int);
	Position getIdArray(void);
	Position getIdArrayPos(int a_id);
	// WARNING CURRENTLY isThereAPlayerOnGameTile does not check if DRAKON IS THERE!
	bool isThereAPlayerOnGameTile(int row, int column);
	bool isThereAPlayerOnGameTile(Position pos);
	Position convertScreenCoordsToGridPos(int mouseX, int mouseY);
	IntInt getPlayerWithMostGoldLost();
	IntInt getPlayerWithLeastGoldLost();
	IntInt getPlayerWithMostGoldGained();
	IntInt getPlayerWithLeastGoldGained();

	// Set Functions
	void initGameStart();
	void shuffleDeck(list<Tile>& tileList);
	void setDeck(list<Tile>&);

	void setBoardTile(Tile tile,int r ,int c, int owner);
	// ASSUMES PLAYERS AREN't ON GameTile
	void removeBoardTileAndPutOnDeck(Position pos);
	void removeGameTile(Position pos);
	void placeTile(Tile a_tile, Position pos, int owner);
	void placeStartTile(Tile a_tile, Position pos);
	
	void setGridFocus(Position a_gridFocus);
	void setGridFocus(int row,int column);
	void setGridStart(Position a_gridStart);
	void setGridStart(int row,int column);
	void setGridStartPos();
	void changeTurn();

	// Draw function
//	void drawPlayerHand(SDL_Surface*,SDL_Surface*,SDL_Surface*);
	void drawPlayerHand(int playerID, SDL_Surface * a_buffer, SDL_Surface * a_tileBGs, SDL_Surface * a_tileIcons);
	void drawBoardTiles(SDL_Surface*,SDL_Surface*,SDL_Surface*,Position);
	void drawGameGrid(SDL_Surface*);
	void drawBoardBG(SDL_Surface*, SDL_Surface*);

	void blit(SDL_Surface* a_source,SDL_Surface* dest,Position position);
	void blit(SDL_Surface* source ,SDL_Surface* dest,int row,int column);

	// Debugger functions
	void printDeck(SDL_Surface *);
	void printScreen(SDL_Surface *);
	void printPlayerHands();
	
	// WARNING : CAN BE MALICIOUS
	void popFrontOfDeck(){ m_deck.pop_front();}
	int getNumPlayers() { return NUMBER_OF_PLAYERS; }
	int getTotalGold(int a_index) { return m_players[a_index].getCoinSack().getGoldTotal();}
private:
	/*--- Game Sub-Functions ---*/
	void setIdArray(void);
	list<Tile>& getCurrPlyrTileList(void);
};